//abstract class database
#ifndef DATABASE_H
#define DATABASE_H

#include<vector>
//for time
#include <string>
#include "newsgroupdoesnotexistexception.h"
#include "articledoesnotexistexception.h"

using namespace std;

namespace client_server{
	class Database{
	public:
		Database() {Database::articleCounter = 0;}
		virtual ~Database() {}
    
		//the neccesary functions for newsgroups
		virtual vector<pair<int, string> > listAllNewsGroups() = 0; 
		virtual void createNewsGroup(const string& name) throw (NewsGroupDoesNotExistException) = 0; 
		virtual void deleteNewsGroup(unsigned int id) throw (NewsGroupDoesNotExistException) = 0;

		//functions for articles
		virtual vector<pair<int,string> > listAllArticles(unsigned int id) throw (NewsGroupDoesNotExistException) = 0;
		virtual void readArticle(unsigned int ngId, unsigned int aId, stringstream& ss) throw (NewsGroupDoesNotExistException, ArticleDoesNotExistException) = 0;
		virtual void createArticle(unsigned int id,const string& content, const string& author=string("unknown"), const string& artName=string("article")) throw (NewsGroupDoesNotExistException) = 0;
		virtual void deleteArticle(unsigned int ngId, unsigned int aId) throw (NewsGroupDoesNotExistException, ArticleDoesNotExistException) = 0;
		
		//manage the number of articles
		void increment(){++articleCounter;}
		unsigned int articleNum(){return articleCounter;}

		void ngIncrement(){++ngCounter;}
		unsigned int ngNum(){return ngCounter;}
		void setNgCounter(unsigned int i){ ngCounter = i;}
	private:  
		//every article should have a unique number
		unsigned int articleCounter;
		unsigned int ngCounter;

		//we don't need copies of our database
		Database(const Database&);
		Database& operator=(const Database&);
  };  
}
#endif
